<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /* 思路：快慢指针 */
      var removeNthFromEnd = function (head, n) {
        let dummy = new ListNode(0)
        let fast = dummy
        let slow = dummy
        while (n--) {
          fast = fast.next
        }
        if (!fast) return dummy.next
        while (fast && fast.next) {
          slow = slow.next
          fast = fast.next
        }
        let next = slow.next.next
        slow.next = next
        return dummy.next
      }
    </script>
  </body>
</html>
